import BaseService from '@/utils/base/service';
import makeRequest from '@/utils/request/request';
import { PrivacyAgreementData } from '../data/index';
import { BaseParamsData } from '../data/index';

export default class LoginModel extends BaseService {
	constructor() {
		super('/unapp/pagehome');  // 设置基础路径和缓存键
	}

	/**
	 * 获取协议列表
	 */
	async getProtocolList() : Promise<PrivacyAgreementData[]> {
		const response = await makeRequest({
			url: `${this.endpoint}/getProtocolList`,
			method: 'GET',
			hideLoading: true
		});
		let array = <PrivacyAgreementData[]>[];
		response.data.forEach((item : PrivacyAgreementData) => {
			array.push(new PrivacyAgreementData(item));
		});
		return array;
	}

	/**
	 * 获取关于我们
	 */
	async getAboutUs() : Promise<PrivacyAgreementData[]> {
		const response = await makeRequest({
			url: `${this.endpoint}/getAboutUs`,
			method: 'GET',
		});
		return response.data.introduce;
	}

	/**
	 * 获取应用配置信息
	 */
	async getBaseParams() : Promise<BaseParamsData> {
		const response = await makeRequest({
			url: `${this.endpoint}/getBaseParams`,
			method: 'GET',
		});
		let data = new BaseParamsData(response.data)
		data.saveCache()
		return data;
	}

	/**
	 * 获取版本号
	 */
	async getVersion() : Promise<string> {
		const response = await makeRequest({
			url: `${this.endpoint}/getUnappLastVersion`,
			method: 'GET',
		});
		return response.data.versionNo;
	}
}